package com.villaday.idf.adapter3;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model2.Presell_list;
import com.villaday.idf.model3.BatchListEntity;


public class HomeBatchAdapter extends AbsRecyclerViewAdapter<BatchListEntity.BodyBean.ListBean> {

    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;

    public HomeBatchAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.recycle_home_batch, R.layout.item_page_loading,R.layout.item_page_bottom);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;
    }

    @Override
    public int getItemType(BatchListEntity.BodyBean.ListBean d) {
        return d.getAddType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, BatchListEntity.BodyBean.ListBean d, int position) {
        try {
            switch (d.getAddType()) {
                case 0:
                    ImageView ivCheck = (ImageView) holder.getView(R.id.iv_hb_check);
                    ivCheck.setTag(position);
                    ivCheck.setOnClickListener(onClickListener);

                    SimpleDraweeView sdHb = (SimpleDraweeView) holder.getView(R.id.sdv_hb);
                    sdHb.setTag(position);
                    sdHb.setOnClickListener(onClickListener);

                    if (!d.isCheck()) {
                        ivCheck.setImageResource(R.drawable.ic_batch_checkbox_normal);
                    } else {
                        ivCheck.setImageResource(R.drawable.ic_batch_checkbox_pre);
                    }
                    holder.bindTextView(R.id.tv_hb_title,d.getName())
                            .bindSimpleDraweeView(R.id.sdv_hb, d.getImageURL());
                    break;
                case 1:
                    onAdapterCallbackListener.onCallback();
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
